package net.wofly.sale.stock.validator;

import net.wofly.sale.stock.domain.ResourceAskList;
import net.wofly.sale.stock.util.ResourceAskStatus;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * Created by LiuJianbo on 2017/10/9.
 */
public class ResourceAskValidator {
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static void validateUserID(StringBuffer stringBuffer, String userID) {
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("用户ID不能为空！").append(lineSeparator);
        }
    }
    
    public static String validateResourceAskListID(String resourceAskListID) {
		StringBuffer stringBuffer = new StringBuffer();
	    if (StringUtils.isEmpty(resourceAskListID)) {
	        stringBuffer.append("领料申请内容ID不能为空！").append(lineSeparator);
	    }
	    
	    return stringBuffer.toString() ;
	}

    public static void validateResourceAskID(StringBuffer stringBuffer, String resourceAskID) {
        if (StringUtils.isEmpty(resourceAskID)) {
            stringBuffer.append("领料申请ID不能为空！").append(lineSeparator);
        }
    }
    
    public static String validateStartWF(String userID, String resourceAskID) {
    		StringBuffer stringBuffer = new StringBuffer();
        if (StringUtils.isEmpty(resourceAskID)) {
            stringBuffer.append("领料申请ID不能为空！").append(lineSeparator);
        }
        if (StringUtils.isEmpty(userID)) {
            stringBuffer.append("申请人ID不能为空！").append(lineSeparator);
        }
        
        return stringBuffer.toString() ;
    }
    
    public static String validateAddResourceAsk(String userID, String commodityTerminalID ,Integer askNum) {
		StringBuffer stringBuffer = new StringBuffer();
    if (StringUtils.isEmpty(commodityTerminalID)) {
        stringBuffer.append("终端商品ID不能为空！").append(lineSeparator);
    }
    if (StringUtils.isEmpty(userID)) {
        stringBuffer.append("申请人ID不能为空！").append(lineSeparator);
    }
    if (StringUtils.isEmpty(askNum)) {
        stringBuffer.append("终端商品数量不能为空！").append(lineSeparator);
    }
    
    return stringBuffer.toString() ;
}

    public static String validateCheckResourceAskParams(String resourceAskID, Integer checkStatus) {
        StringBuffer stringBuffer = new StringBuffer();
        validateResourceAskID(stringBuffer, resourceAskID);
        if (checkStatus == null) {
            stringBuffer.append("审核状态不能为空").append(lineSeparator);
        }
        if (ResourceAskStatus.审核通过.getValue().intValue() != checkStatus && ResourceAskStatus.驳回.getValue().intValue()
                != checkStatus) {
            stringBuffer.append("审核状态参数值不正确").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateResourceAskID(String resourceAskID) {
        StringBuffer stringBuffer = new StringBuffer();
        validateResourceAskID(stringBuffer, resourceAskID);
        return stringBuffer.toString();
    }

    public static String validateSaveResourceAskParams(
            @RequestBody List<ResourceAskList> resourceAskLists, String asker) {
        StringBuffer stringBuffer = new StringBuffer();

        if (StringUtils.isEmpty(asker)) {
            stringBuffer.append("申请人不能为空").append(lineSeparator);
        }
        if (CollectionUtils.isEmpty(resourceAskLists)) {
            stringBuffer.append("领料内容不能为空").append(lineSeparator);
        } else {
            for (ResourceAskList resourceAskList : resourceAskLists) {
                if (StringUtils.isEmpty(resourceAskList.getCommodityTerminalID())) {
                    stringBuffer.append("领料内容 -- 终端商品ID不能为空").append(lineSeparator);
                }
                if (resourceAskList.getAskNum() == null) {
                    stringBuffer.append("领料内容 -- 商品申请数量不能为空").append(lineSeparator);
                }
            }
        }

        return stringBuffer.toString();
    }

    public static String validateGetResourceAskListParams(String askNO, String askUserID, Integer askStatus) {
        StringBuffer stringBuffer = new StringBuffer();
        return stringBuffer.toString();
    }

    public static String validateGetResourceAskParams(String resourceAskID) {
        StringBuffer stringBuffer = new StringBuffer();
        validateResourceAskID(stringBuffer, resourceAskID);
        return stringBuffer.toString();
    }
}
